package com.inmaytide.website.mapper.deploy;

import com.inmaytide.website.domain.entities.deploy.DeployInfo;
import com.inmaytide.website.domain.vo.deploy.DeployInfoVo;
import com.inmaytide.website.mapper.deploy.provider.DeployInfoMapperSQLProvider;
import com.inmaytide.website.utils.pagination.Pagination;
import org.apache.ibatis.annotations.*;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;
import java.util.Map;

public interface DeployInfoMapper extends Mapper<DeployInfo> {

    @Select({
            "SELECT seq from SQLITE_SEQUENCE where name = 'deploy_info'"
    })
    public long getLastInsertId();

    @Select({
            "select * from deploy_info order by id desc"
    })
    @Results({
            @Result(column = "project_id", property = "projectId"),
            @Result(column = "project_name", property = "projectName"),
            @Result(column = "project_path", property = "projectPath"),
            @Result(column = "backup_path", property = "backupPath"),
            @Result(column = "operate_user", property = "operateUser"),
            @Result(column = "operate_ip", property = "operateIp"),
            @Result(column = "operate_time", property = "operateTime"),
            @Result(column = "unzip_count", property = "unzipCount"),
            @Result(column = "backup_count", property = "backupCount"),
            @Result(column = "deploy_count", property = "deployCount")
    })
    List<DeployInfo> findList();

    /**
     * 查询数量
     *
     * @param condition
     * @return
     */
    @SelectProvider(type = DeployInfoMapperSQLProvider.class, method = "findCountByCondition")
    public int findCountByCondition(@Param("condition") Map<String, String> condition);

    /**
     * 查询分页
     *
     * @param pagination
     * @return
     */
    @SelectProvider(type = DeployInfoMapperSQLProvider.class, method = "findListByPagination")
    @Results({
            @Result(column = "project_id", property = "projectId"),
            @Result(column = "project_name", property = "projectName"),
            @Result(column = "project_path", property = "projectPath"),
            @Result(column = "backup_path", property = "backupPath"),
            @Result(column = "operate_user", property = "operateUser"),
            @Result(column = "operate_user_name", property = "operateUserName"),
            @Result(column = "operate_ip", property = "operateIp"),
            @Result(column = "operate_time", property = "operateTime"),
            @Result(column = "unzip_count", property = "unzipCount"),
            @Result(column = "backup_count", property = "backupCount"),
            @Result(column = "deploy_count", property = "deployCount")
    })
    List<DeployInfoVo> findListByPagination(@Param("pagination") Pagination<DeployInfoVo> pagination);

}